package com.music.pay.config;


import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
@EnableConfigurationProperties(AlipayProperties.class)
public class AlipayConfig {
    @Bean
    public AlipayClient alipayClient(AlipayProperties alipayProperties) {
        System.out.println("-------------->"+alipayProperties.getAppId());
        return new DefaultAlipayClient(alipayProperties.getServerUrl(), alipayProperties.getAppId(),
                alipayProperties.getPrivateKey(), alipayProperties.getFormat(), alipayProperties.getCharset(),
                alipayProperties.getAlipayPublicKey(), alipayProperties.getSignType());
    }

    // 设置请求参数
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public AlipayTradePagePayRequest alipayRequest(AlipayProperties alipayProperties) {
        System.out.println("-------------->"+alipayProperties.getAppId());
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(alipayProperties.getReturnUrl());
        alipayRequest.setNotifyUrl(alipayProperties.getNotifyUrl());
        return alipayRequest;
    }
}
